﻿using Permissions.Employee_RoleApp;
using Permissions.Employee_RoleApp.Dto;
using Permissions.EmployeeApp.Dto;
using Permissions.RoleApp;
using Permissions.RoleApp.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Permissions.Web.Controllers
{
    public class Employee_RoleController : Controller
    {
        private readonly IEmployee_RoleAppService _employeeRoleRepository;
        private readonly IRoleAppService _roleRepository;

        public Employee_RoleController(IEmployee_RoleAppService employeeRoleRepository, IRoleAppService roleRepository)
        {
            _employeeRoleRepository = employeeRoleRepository;
            _roleRepository = roleRepository;
        }

        // GET: Employee_Role
        public ActionResult Index()
        {
            var roles = _roleRepository.GetRoles();

            return View(roles);
        }
        public string Employee_Role(string Id)
        {
            var employeeRoles = _employeeRoleRepository.GetEmployees_Role(int.Parse(Id));
            string json = "{\"code\":\"0\",\"data\":[";

            foreach (var item in employeeRoles.Items)
            {
                json += "{\"Id\":\"" + item.Role.Id + "\"},";
            }
            json = json.TrimEnd(',');
            json += "]}";

            return json;
        }

        public string AddEmployee_Role(EmployeeDto employeeDto, RoleDto roleDto)
        {
            //var Id = input.Employee.Id;
            //var role=input.Role.Id;
            //_employeeRoleRepository.CreateEmployee_Role();

            return "成功！";
        }
    }
}